package com.itheima.skyserver.mapper;

import com.github.pagehelper.Page;
import com.itheima.skyserver.pojo.domain.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {
    @Select("select * from employee where username = #{username};")
    Employee selectByUsername(String username);

    Page<Employee> selectByCondition(String name);

    @Update("update employee SET status = #{status} where id = #{id};")
    void setStatus(Integer status, Long id);

    @Insert("insert into employee (id_number, name, phone, sex, username, create_time, update_time, create_user, update_user) values (#{idNumber}, #{name}, #{phone}, #{sex}, #{username}, now(), now(), #{createUser}, #{updateUser});")
    void insertEmployee(Employee employee);

    @Select("select * from employee where id = #{id};")
    Employee selectEmployeeById(Long id);

    @Update("update employee set id_number = #{idNumber}, name = #{name}, phone = #{phone}, sex = #{sex}, username = #{username}, update_time = now(), update_user = #{updateUser} where id = #{id};")
    void updateEmployee(Employee employee);

    @Update("update employee set password = #{newPassword} where id = #{empId};")
    void editPassword(Long empId, String newPassword);
}
